#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
图标工具模块

提供图标创建和转换功能
"""

try:
    import ttkbootstrap as ttk
    from ttkbootstrap.icons import Icon
    import base64
    from io import BytesIO
    from PIL import Image, ImageTk
    BOOTSTRAP_AVAILABLE = True
except ImportError:
    BOOTSTRAP_AVAILABLE = False


def create_icon_image(icon_data):
    """将base64图标数据转换为PhotoImage对象"""
    if not BOOTSTRAP_AVAILABLE:
        return None
    try:
        # 解码base64数据
        icon_bytes = base64.b64decode(icon_data)
        
        # 创建PIL图像
        pil_image = Image.open(BytesIO(icon_bytes))
        
        # 转换为PhotoImage
        photo_image = ImageTk.PhotoImage(pil_image)
        
        return photo_image
    except Exception as e:
        print(f"创建图标失败: {e}")
        return None


def get_icon_info():
    """获取info图标"""
    if BOOTSTRAP_AVAILABLE:
        return create_icon_image(Icon.info)
    return None


def get_icon_error():
    """获取error图标"""
    if BOOTSTRAP_AVAILABLE:
        return create_icon_image(Icon.error)
    return None


def get_icon_warning():
    """获取warning图标"""
    if BOOTSTRAP_AVAILABLE:
        return create_icon_image(Icon.warning)
    return None


def get_icon_question():
    """获取question图标"""
    if BOOTSTRAP_AVAILABLE:
        return create_icon_image(Icon.question)
    return None
